<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="请输入所在区域" prop="localName">
        <el-input v-model="formData.localName" placeholder="请输入"  show-word-limit clearable
                  :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="telphone">
        <el-input v-model="formData.telphone" placeholder="请输入手机号" :maxlength="11" show-word-limit clearable
          prefix-icon='el-icon-mobile' :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input v-model="formData.idCard" placeholder="请输入身份证号" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="体温情况" prop="temperature">
        <el-input v-model="formData.temperature" placeholder="请输入体温情况" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="健康码颜色" prop="heathCode">
        <el-radio-group v-model="formData.heathCode" size="medium">
          <el-radio v-for="(item, index) in field110Options" :key="index" :label="item.value"
            :disabled="item.disabled">{{item.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="健康码截屏">
        <el-upload
            class="upload-demo"
            :action="'http://' + serverIp + ':8081/file/upload'"
            multiple
            :on-success="handleAvatarSuccess"
            :limit="1">
          <el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
        </el-upload>
      </el-form-item>
      <el-form-item label="进出选择" prop="state">
        <el-radio-group v-model="formData.state" size="medium">
          <el-radio v-for="(item, index) in field113Options" :key="index" :label="item.value"
            :disabled="item.disabled">{{item.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="进出目的" prop="remarks">
        <el-input v-model="formData.remarks" type="textarea" placeholder="请输入进出目的"
          :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
      </el-form-item>

      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {serverIp} from "../../public/config";

export default {
  components: {},
  props: [],
  data() {
    return {
      serverIp:serverIp,
      formData: {},
      rules: {
        localName: [{
          required: true,
          message: '请选择区域场所',
          trigger: 'change'
        }],
        telphone: [{
          required: true,
          message: '请输入手机号',
          trigger: 'blur'
        }, {
          pattern: /^1(3|4|5|7|8|9)\d{9}$/,
          message: '手机号格式错误',
          trigger: 'blur'
        }],
        idCard: [{
          required: true,
          message: '请输入身份证号',
          trigger: 'blur'
        }, {
          pattern: /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
          message: '请输入正确的身份证号码',
          trigger: 'blur'
        }],
        temperature: [{
          required: true,
          message: '请输入体温情况',
          trigger: 'blur'
        }],
        heathCode: [{
          required: true,
          message: '健康码颜色不能为空',
          trigger: 'change'
        }],
        state: [{
          required: true,
          message: '进出选择不能为空',
          trigger: 'change'
        }],
        remarks: [{
          required: true,
          message: '请输入进出目的',
          trigger: 'blur'
        }],
      },
      field117Options: [],
      field110Options: [{
        "label": "绿码",
        "value": "绿码"
      }, {
        "label": "黄码",
        "value": "黄码"
      }, {
        "label": "红码",
        "value": "红码"
      }, {
        "label": "弹窗",
        "value": "弹窗"
      }, {
        "label": "其他",
        "value": "其他"
      }],
      field113Options: [{
        "label": "进",
        "value": "进"
      }, {
        "label": "出",
        "value": "出"
      }],
      field117Props: {
        "multiple": false
      },
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
        this.request.post("/t-access/",this.formData).then(res =>{
          if (res.code === 200){
            this.$message.success("提交成功")
          }
          if (res.code === -200){
            this.$message.warning(res.message)
          }
        })
      })
    },
    handleAvatarSuccess(res){
      this.formData.heathImg=res
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
    getField117Options() {
      // TODO 发起请求获取数据
      this.field117Options
    },
    field108BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 5
      if (!isRightSize) {
        this.$message.error('文件大小超过 5MB')
      }
      let isAccept = new RegExp('image/*').test(file.type)
      if (!isAccept) {
        this.$message.error('应该选择image/*类型的文件')
      }
      return isRightSize && isAccept
    },
  }
}

</script>
<style>
.el-upload__tip {
  line-height: 1.2;
}

</style>
